//
//  BaseTabBarController.swift
//  自定义tabbar和navigationbar
//
//  Created by xiaoyi on 2020/4/24.
//  Copyright © 2020 lete. All rights reserved.
//

import UIKit

class BaseTabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        
        self.setChildTabbar()
        
    }
    
    
    func setChildTabbar() -> Void {
        
        //创建一个页面(Storyboard)
        let sb = UIStoryboard(name: "Home", bundle: nil)
        let homeVC = sb.instantiateViewController(withIdentifier: "LTHomeViewController") as! LTHomeViewController
        let baseV = self.setChildViewController(vc: homeVC, title: "首页", image: "social_github", selectedImage: "social_github_un")
        let A = self.setChildViewController(vc: ViewController.init(), title: "A", image: "social_twitter", selectedImage: "social_twitter_un")
        
        let mineVC = self.setChildViewController(vc: LTMineViewController.init(), title: "我的", image: "social_wechat", selectedImage: "social_wechat_un")
        
        self.viewControllers = [baseV, A, mineVC]
        
        tabBar.barTintColor = UIColor.white
        tabBar.backgroundColor = UIColor.white
        
        
    }
    
    //    设置子viewController的title，image，selectedImage，设置了防止图片被渲染
    //    都添加了自定义的navbar
    
    func setChildViewController(vc: UIViewController, title: NSString, image:NSString, selectedImage: NSString) -> UIViewController {
        let Nav = BaseNavigationController.init(rootViewController: vc)
        Nav.tabBarItem.title = title as String
        Nav.tabBarItem.image = UIImage.init(named: image as String)?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)
        Nav.tabBarItem.selectedImage = UIImage.init(named: selectedImage as String)?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)
        
        return Nav
        
    }
    
    
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destination.
     // Pass the selected object to the new view controller.
     }
     */
    
}
